<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/own.css" rel="stylesheet" />
		<style type="text/css">
			.st_cot {
				font-size: 0.65rem;
				line-height: 0.7rem;
				background: #FFFFFF;
				border: none;
				width: 70%;
				color: #50CEBD;
			}

			.mui-table-view-cell {
				line-height: 1.4rem;
			}

			.mui-table-view-cell.mui-active {
				background: transparent;
			}

			.value-holder {
				color: #333333;
				padding-left: 0.3rem;
			}

			#div_button {
				background: #007aff;
				color: #ffffff;
				font-size: 0.8rem;
				padding: 0.5rem 1rem;
				border-radius: 0.7rem;
				margin: 2rem 0.5rem;
				text-align: center;
			}

			.mui-table-view-cell span {
				font-size: 0.7rem;
			}

			.zt_size {
				font-size: 0.75rem;
				/* margin-left:18%; */
			}

			span.zt_size {
				font-size: 0.75rem;
			}

			#zt_span {
				height: 1.6rem;
				display: inline-block;
				background: #007aff;
				color: #ffffff;
				font-size: 0.65rem;
				padding: 0 0.1rem;
				border-radius: 0.2rem;
				line-height: 1.8rem;
				width: 3rem;
				margin-left: 1rem;
				text-align: center;

			}

			input.zb_ys {
				color: #333333;
				width: 80%;
				height: 1.8rem;
				padding: 0rem 0rem;
				margin: 0rem;
				font-size: 0.65rem;
				text-align: center;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar own-mui-bar-nav own-main-background-color ">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left "></a>
			<h1 class="mui-title">新增试验检测点</h1>
			<span class="mui-icon mui-icon-location  mui-pull-right" id="zuobiao" style="font-size: 0.7rem;line-height: 1.2rem;color: #FFFFFF">获取坐标</span>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view " style="font-size: 0.65rem;">
				<li class="mui-table-view-cell">
					<div class="mui-inline zt_size">相对密度:</div>
					<div class="value-holder mui-inline">
						<input id="md" type="number" style="color: #333333;width: 80%;height:1rem;padding:0rem 0rem;margin:0rem ;border: none;font-size: 0.65rem;"
						 placeholder="请输入相对密度" />
					</div>

				</li>
				<li class="mui-table-view-cell">
					<div class="mui-inline zt_size">孔隙率:</div>
					<div class="value-holder mui-inline">
						<input id="kxl" type="number" style="color: #333333;width: 80%;height:1rem;padding:0rem 0rem;margin:0rem ;border: none;font-size: 0.65rem;"
						 placeholder="请输入孔隙率" />
					</div>

				</li>
				<li class="mui-table-view-cell">
					<div class="mui-inline" id="zbdata">
						<div class="mui-inline zt_size" style="margin-top: 0.6rem;">坐标:</div>
						<div class="mui-inline" style="width: 30%;margin-top: 0.2rem;"><input type="number" class="zb_ys" id="lon1" /></div>
						<div class="mui-inline" style="width: 30%;margin-top: 0.2rem;"> <input type="number" class="zb_ys" id="lat1" /></div>
					</div>
				</li>
			</ul>

			<div id="div_button">保存</div>
		</div>

		<script src="../js/mui.min.js"></script>
		<script src="../js/common.js"></script>
		<script src="../js/jquery-1.7.2.min.js"></script>
		<script src="../js/BluetoothTool.js"></script>


		<script type="text/javascript">
			mui.init();

			var indexview = null;

			var syid = null;
			var uid = null;
			var layer = null;

			var num = 1;

			var wo = null;
			/* 蓝牙 */
			var bluetoothTool = null;

			var receiveDataArr = [];

			var jingweidu = null;

			mui.plusReady(function() {
                /* 蓝牙 */
                bluetoothTool = BluetoothTool();
				
				indexview = plus.webview.currentWebview();

				wo = indexview.opener();

				syid = indexview.data;
				uid = indexview.path;
				layer = indexview.thParam;
                 
				
				 
				 if(!isNull(syid)){
					 querycdinfo();
				 }
				 
				 
				document.getElementById('div_button').addEventListener('tap', function() {
					savedata();
				});

				

				bluetoothTool.init({
					readDataCallback: function(dataByteArr) {
						if (receiveDataArr.length >= 240) {
							jingweidu = String.fromCharCode.apply(String, receiveDataArr);
							receiveDataArr = [];
						}
						receiveDataArr.push.apply(receiveDataArr, dataByteArr);
					}
				});
				
				document.getElementById('zuobiao').addEventListener('tap', function() {
					plus.nativeUI.showWaiting('获取中...');
					if (bluetoothTool.getPairedDevices().length > 0 && bluetoothTool.getPairedDevices()[0].name.indexOf('BDXGX') != -
						1) {
						bluetoothTool.connDevice(bluetoothTool.getPairedDevices()[0].address);
						setTimeout(function() {
							bluetoothTool.disConnDevice();
							if (jingweidu) {
								if (jingweidu.indexOf('$PTNL') != -1 && jingweidu.indexOf('$KSXT') != -1) {
									var str01 = jingweidu.split('$KSXT,')[1];
									var str02 = str01.split(',');
									if (str02.length > 2) {
										var params = {
											'node': localStorage.getItem('node'), //节点编号
											'lon': str02[1],
											'lat': str02[2],
											'h': str02[3]
										};
				
										mpms_ajax_noWaiting(params, 'coordTrans', function(data) {
											if (data.status == '0') {
												$('#lon' + num).val(data.data.N);
												$('#lat' + num).val(data.data.E);
												plus.nativeUI.closeWaiting();
											} else {
												plus.nativeUI.closeWaiting();
												mui.toast(data.msg);
											}
										});
									} else {
										plus.nativeUI.closeWaiting();
										mui.toast('请重新获取值');
									}
				
								} else {
									plus.nativeUI.closeWaiting();
									mui.toast('请重新获取值');
								}
							} else {
								mui.toast('请重新获取值');
								plus.nativeUI.closeWaiting();
							}
						}, 5000);
				
					} else {
						plus.nativeUI.closeWaiting();
						mui.toast('蓝牙连接设备错误，请重新连接');
					}
				})

			});
           
		   function querycdinfo() {
		   	var params = {
		   		'node': localStorage.getItem('node'), //节点编号
		   		'uid': uid,
		   		'layer': layer,
		   	};
		   	mpms_ajax(params, 'getPieceCheck', function(data) {
		   		if (data.status == '0') {
		   			if (!isNull(data.data)) {
		   				syid = data.data.id;
		   				$('#md').val(data.data.dr);
		   				$('#kxl').val(data.data.kxl);
		   				$('#ctime').text(getdate(data.data.ctime));
		   			}
		   		} else {
		   			mui.toast(data.msg);
		   		}
		   	});
		   }
			//保存单元工程
			function savedata() {
				getPagetoken();
				var dr = $('#md').val();
				var kxl = $('#kxl').val();
				var lon1 = $('#lon1').val();
				var lat1 = $('#lat1').val();
				if (isNull(dr) && isNull(kxl)) {
					mui.toast('请输入相对密度或者孔隙率');
					return;
				}
				// if (isNull(kxl)) {
				// 	mui.toast('请输入孔隙率');
				// 	return;
				// }
                if (isNull(lon1)) {
                	mui.toast('请先获取坐标');
                	return;
                }
				var params = {
					'id':syid,
					'node': localStorage.getItem('node'), //节点编号
					'uid': uid, 
					'layer': layer, 
					'kxl': kxl,
					'dr':dr,
					'n': lon1,
					'e':lat1
				};
             
				mpms_ajax(params, 'pieceCheckPos', function(data) {
					if (data.status == '0') {
						mui.toast('保存成功');
						wo.evalJS("querysylist()");
						mui.back();
					} else {
						mui.toast(data.msg);
					}
				});

			}

			
		</script>
	</body>

</html>
